#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 17:45
# @Author: 张涛
# @Email: xxx@gmail.com
# @File：com_opt_page.py

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select  #引入Select
from pages.base_page import BasePage

class ComOptPage(BasePage):
    ssxlk_a_locator = (By.ID,'field')  #搜索下拉框1
    ssxlk_b_locator = (By.ID,'condition') #搜索下拉框2
    ssssk_locator = (By.ID,'search')  #搜索输入框
    ssan_locator = (By.ID,'dosearch') #搜索按钮
    sjm_a_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[4]/a/span') #商机名1
    sjm_b_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[2]/td[4]/a/span') #商机名2
    tjsj_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[1]/div/a') #添加商机
    sjgj_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[1]/div/div/button') #商机工具
    cksj_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[12]/a[1]') #商机查看
    sjtj_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[12]/a[2]') #商机推进
    qjdjd_locator = (By.XPATH,'/html/body/div[8]/div[2]/form/table/tbody/tr[2]/td[2]/select')  #定位推进商机 - 前进到阶段

    sjbj_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[12]/a[3]') #商机编辑
    sjtongji_locator = (By.XPATH,'/html/body/div[5]/div[1]/ul/li[2]/a') #商机统计
    dcsj_locator = (By.ID,'excelExport') #导出商机
    sjcjr_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[9]/a') #商机创建人
    scshnagji_locator = (By.CSS_SELECTOR,'#delete') #定位删除商机
    qbgxk_locator = (By.ID,'check_all') #全部勾选框
    actual_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(4) > a > span')  # 获取当前页面商机名
    susjm_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr > td:nth-child(4) > a > span')  #获取搜索当前商机名
    sjsujv_locator = (By.XPATH,'/html/body/div[5]/div[3]/div[1]/ul/li[1]/a') #全部删除后出现的商机数据

    def xlk_a_element(self,xlk_a):
        '''选择下拉框a'''
        ssxlk_a = self.driver.find_element(*self.ssxlk_a_locator)
        Select(ssxlk_a).select_by_visible_text(xlk_a)

    def xlk_b_element(self,xlk_b):
        '''选择下拉框b'''
        ssxlk_b = self.driver.find_element(*self.ssxlk_b_locator)
        Select(ssxlk_b).select_by_visible_text(xlk_b)

    def sssrk_element(self,sssrk_a):
        '''输入搜索内容'''
        self.driver.find_element(*self.ssssk_locator).send_keys(sssrk_a)

    def ssan_element(self):
        '''点击搜索按钮'''
        self.driver.find_element(*self.ssan_locator).click()

    def dyh_sjm(self):
        '''获取第一行商机名'''
        sjm_a = self.driver.find_element(*self.sjm_a_locator).text
        return sjm_a

    def yeh_sjm(self):
        '''取的二行商机名'''
        sjm_b = self.driver.find_element(*self.sjm_b_locator).text
        return sjm_b

    def tjsj_elemene(self):
        '''点击添加商机'''
        self.driver.find_element(*self.tjsj_locator).click()

    def sjgj_element(self):
        '''点击商机工具'''
        self.driver.find_element(*self.sjgj_locator).click()

    def sjck_element(self):
        '''点击查看商机'''
        self.driver.find_element(*self.cksj_locator).click()

    def sjtj_element(self):
        '''点击商机推进'''
        self.driver.find_element(*self.sjtj_locator).click()

    def bjtjsj_element(self,tjzt):
        """推进下拉框选择"""
        qjdjd =  self.driver.find_element(*self.qjdjd_locator)
        Select(qjdjd).select_by_visible_text(tjzt)

    def sjbj_element(self):
        '''点击商机编辑'''
        self.driver.find_element(*self.sjbj_locator).click()

    def tongji_element(self):
        '''点击统计'''
        self.driver.find_element(*self.sjtongji_locator).click()

    def dcsj_element(self):
        '''点击导出商机'''
        self.driver.find_element(*self.dcsj_locator).click()

    def sjcsr_element(self):
        '''点击商机创始人'''
        self.driver.find_element(*self.sjcjr_locator).click()

    def scsj_element(self):
        '''点击删除'''
        self.driver.find_element(*self.scshnagji_locator).click()

    def gxqbsc_element(self):
        '''勾选全部商机'''
        self.driver.find_element(*self.qbgxk_locator).click()

    def dqsjm_element(self):
        '''获取当前商机名称'''
        actual = self.driver.find_element(*self.actual_locator).text
        return actual

    def susjm_element(self):
        '''获取搜索商机名'''
        susjm = self.driver.find_element(*self.susjm_locator).text
        return susjm

    def sjsujv_element(self):
        '''获取全部删除后页面文本'''
        sjsujv = self.driver.find_element(*self.sjsujv_locator).text
        return sjsujv                  #获取预期数据

